var windowName = "match";
var Page ,LiveList,idCheckLocal,map
apiready = function(){

    map = api.require('bMap');
    onWindowHide(function () {
    })
    console.log("index page is OK");
    LiveList = new List();
    Page = createVM("#Page",{
        //页面数据

        banner:[
            {pic:picBanner,action:""}
        ]
        ,announce:[]
        ,curTab:0,
        distanceOpen:false,
        timeOpen:false,

        //匹配任务相关
        list:[]
        ,listVote:[]
        ,listHire:[]
        ,listDone:[]
        ,listLog:[]

        ,status:{
            login:1
        }
    },{
        //页面方法
        "init":function () {
            var banner = getLocData("bannerMatch")
            if (isTrue(banner)) {
                this.banner = banner
            }
            var data =getData4Page()
            console.log(data.text);

        }
        ,tab:function (index) {
            log(index)
            Page.curTab = index
            Page.subjectId = index
            if (index == 0) {
                getData()
            }
            if (index == 1) {
                apiGet("/app/shop/task/vote",{},function (res , code) {
                    logJson(res,"vote:_")
                    if (code == 200){
                        Page.listVote = res.data
                    }else {
                        showToast(code)
                    }

                })
            }
            if (index == 2) {
                apiGet("/app/shop/task/hire",{},function (res , code) {
                    logJson(res,"hire_:_")
                    if (code == 200){
                        Page.listHire = res.data
                    }else {
                        showToast(code)
                    }

                })
            }
            // if (index == 3) {
            //     apiGet("/app/shop/task/done",{},function (res , code) {
            //         logJson(res,"listDone:_")
            //         if (code == 200){
            //             Page.listDone = res.data
            //         }else {
            //             showToast(code)
            //         }
            //
            //     })
            // }
            if (index == 3) {
                apiGet("/app/shop/task/missed",{},function (res , code) {
                    logJson(res,"listDone:_")
                    if (code == 200){
                        Page.listDone = res.data
                    }else {
                        showToast(code)
                    }

                })
            }
            if (index == 4) {
                apiGet("/app/shop/task/votelog",{},function (res , code) {
                    logJson(res,"listDone:_")
                    if (code == 200){
                        Page.listLog = res.data
                    }else {
                        showToast(code)
                    }

                })
            }
        }
        ,"OnPullUpLoadMore":function () {
            LiveList.getList()
        }

        , openShop: function () {
            apiPost("/app/open/shop",{},function (res,code) {
                if (code == 200) {
                    showToast(res.message)

                    //更新用户状态
                    checkUserStatus(function (data) {
                        logJson(data)
                        Page.status = data;
                    })
                }

            })
        }
    })

    Page.init()
}
function updateWinData() {
    var banner = getLocData("bannerMatch")
    logJson(banner,"bannerMatch")
    if (isTrue(banner)) {
        Page.banner = banner
    }
    var announce = getLocData("announce");if (isTrue(announce))Page.announce = announce;
    apiGet("/app/announce",{event:[1]},function (res,code) {
        logJson(res,"announce_")
        if (code == 200) {
            Page.announce = res.data;
            setLocData("announce",Page.announce);
        }
    })
    getData()


    //更新用户状态
    checkUserStatus(function (data) {
        logJson(data)
        Page.status = data;
    })
}
function getData() {
    showLoading();
    var lat = getLocData("lat");
    var lon = getLocData("lon");
    apiGet("/app/shop/task/match",{lat:lat,lon:lon},function (res , code) {
        clearLoading();
        if (code == 200){
            Page.list = res.data
        }else {
            showToast(code)
        }

    })
}
